package com.heima.controller;

import com.heima.pojo.dto.TbSkuDTO;
import com.heima.pojo.dto.TbSkuQueryDTO;
import com.heima.pojo.entity.TbSku;
import com.heima.pojo.vo.TbSkuPageVO;
import com.heima.service.ProductMService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/vm-service/sku")
public class ProductMController {
    @Autowired
    private ProductMService productMService;


    @PostMapping
    public boolean addSkuClass(@RequestBody TbSkuDTO tbSkuDTO){
        return productMService.addSkuClass(tbSkuDTO);
    }
    @GetMapping("/search")
    public TbSkuPageVO search(TbSkuQueryDTO tbSkuQueryDTO){

        return productMService.search(tbSkuQueryDTO);
    }
    @PutMapping("/{skuId}")
    public boolean updateSkuClass(@PathVariable String skuId, @RequestBody TbSkuDTO tbSkuDTO){
        TbSku tbSku = new TbSku();
        BeanUtils.copyProperties(tbSkuDTO,tbSku);
        return productMService.updateSkuClass(skuId,tbSku);
    }
}
